package com.example.mypra1.fragments;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.GridLayout;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.bumptech.glide.Glide;
import com.example.mypra1.LoveActivity;
import com.example.mypra1.PersonalityActivity;
import com.example.mypra1.R;
import com.hacknife.carouselbanner.Banner;
import com.hacknife.carouselbanner.CarouselBanner;
import com.hacknife.carouselbanner.interfaces.CarouselImageFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * 测测模块
 */
public class MainFragment2 extends Fragment {

    private Context mContext;
    private View rootView;
    private ViewGroup mContentView;
    private CarouselBanner banner;
    private List<String>list = new ArrayList<>();
    private Button xinge,hunyin;

    public static MainFragment2 newInstance() {
        Bundle args = new Bundle();
        MainFragment2 fragment = new MainFragment2();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        this.mContext = context;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (rootView == null) {
            rootView = inflater.inflate(R.layout.main_fragment2, container, false);
        }
        //轮播图实现
        banner = rootView.findViewById(R.id.banner);
        list.add("http://8.142.19.67:3000/images/b1.jpeg");
        list.add("http://8.142.19.67:3000/images/b2.jpeg");
        list.add("http://8.142.19.67:3000/images/b3.jpeg");
        Banner.init(new CarouselImageFactory() {
            @Override
            public void onLoadFactory(String url, ImageView view) {
                Glide.with(view).load(url).into(view);
            }
        });
        banner.initBanner(list);
        xinge = rootView.findViewById(R.id.xinge);
        xinge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext.getApplicationContext(), PersonalityActivity.class);
                startActivity(intent);
            }
        });
        hunyin = rootView.findViewById(R.id.hunyin);
        hunyin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext.getApplicationContext(), LoveActivity.class);
                startActivity(intent);
            }
        });

        return rootView;
    }

}
